package ln.javatest.day08.demo07;

public class Computer {
    public void powerOn(){
        System.out.println("笔记本电脑开机");
    }
    public void powerOff(){
        System.out.println("笔记本电脑关机");
    }
    //使用USB设备的方法,使用接口作为方法的参数
    public void useDevice(USB usb){
        usb.open();  //打开设备
        if(usb instanceof Mouse){  //向下转型一定要先判断
            Mouse mouse = (Mouse) usb;
            mouse.click();
        }else if(usb instanceof keyBoard){
            keyBoard keyboard = (keyBoard) usb;
            keyboard.click();
        }
        usb.close(); //关闭设备
    }
}
